
$().ready(function() {
    validatePwdRule();
});

$.validator.setDefaults({
    submitHandler : function() {
        restPwd();
    }
});

function restPwd() {
    var pwdNew = $("#adminUserForm").find("input[name=pwdNew]").val();
    var againPwd = $("#adminUserForm").find("input[name=againPwd]").val();
    if(againPwd!=pwdNew){
        parent.layer.msg("两次输入的密码不对");
    }else{
        console.log("12312312312312312");
        $.ajax({
            cache : true,
            type : "POST",
            url : ctx+"/sys/user/resetPwd",
            data : $('#adminUserForm').serialize(),// 你的formid
            async : false,
            error : function(request) {
                parent.layer.alert("Connection error");
            },
            success : function(data) {
                if (data.code == 0) {
                    parent.layer.msg("修改成功");
                    window.location.replace(ctx+"/logout");
                    var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                    parent.layer.close(index);

                } else {
                    parent.layer.alert(data.msg)
                }

            }
        });
    }
}

function validatePwdRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#adminUserForm").validate({
        rules : {
            pwdNew : {
                required : true
            }
        },
        messages : {
            pwdNew : {
                required : icon + "请输入密码"
            }
        }
    })
}
